package com.app.model.util;


import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * Campus com.app.model.util
 *
 * @author Lichaojie
 * @version 2018/5/3 10:31
 */
public enum UserTitle {

	TITLE0(0,"LV0.萌新小白"),
	TITLE1(10000,"LV1.海边沙沙"),  TITLE2(15000,"LV2.红色石子"),  TITLE3(20000,"LV3.坚韧黑铁"),  TITLE4(30000,"LV4.顽强青铜"),
	TITLE5(40000,"LV5.傲气白银"),  TITLE6(55000,"LV6.聪慧黄金"),  TITLE7(70000,"LV7.巧思白金"),  TITLE8(85000,"LV8.睿智黑金"),
	TITLE9(100000,"LV9.无暇钻石"), TITLE10(120000,"LV10.智者大师"),TITLE11(140000,"LV11.万卷宗师"),TITLE12(165000,"LV12.博学史诗"),
	TITLE13(190000,"LV13.智慧传说"),TITLE14(200000,"LV14.绝对王者");

	private int value;
	private String title;

	UserTitle(int value,String title){
		this.value = value;
		this.title = title;
	}

	public static String title(int value){
		UserTitle[] titles = UserTitle.values();
		List<UserTitle> titleList = Arrays.asList(titles);
		Collections.reverse(titleList);
		for (UserTitle title : titleList){
			if(value > title.value){
				return title.title;
			}
		}
		return TITLE0.title;
	}

	public static double getPercent(int value){
		if(value >= TITLE14.value){
			return 1;
		}

		UserTitle[] titles = UserTitle.values();
		List<UserTitle> titleList = Arrays.asList(titles);
		Collections.reverse(titleList);
		UserTitle lastTitle = TITLE14;
		for (UserTitle title : titleList){
			if(value >= title.value){
				return (value - title.value) * 1.0 / (lastTitle.value - title.value);
			}else {
				lastTitle = title;
			}
		}

		return value * 1.0 / TITLE1.value;
	}

	public static void main(String[] args){
		//title(2);
	}
}
